package com.itzhigui.controller;

import com.itzhigui.entity.Student;
import com.itzhigui.service.StudentService;
import com.itzhigui.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author java1412
 * @since 2023-11-01 17:19:05
 */
@RestController
@Slf4j
// 允许当前的控制器中所有接口可以被其他的服务器直接访问，允许跨域
@CrossOrigin
public class StudentController {
    @Resource
    private StudentService studentService;

    @RequestMapping(value = "/student/findAll")
    public ResponseUtil findAll() {
        return studentService.findAll();
    }

    @RequestMapping(value = "/student/findById/{id}")
    public ResponseUtil findById(@PathVariable("id") Integer id) {
        return studentService.findById(id);
    }

    @RequestMapping(value = "/student/add")
    public ResponseUtil add(Student student) {
        return studentService.add(student);
    }

    @RequestMapping(value = "/student/update")
    public ResponseUtil update(Student student) {
        return studentService.update(student);
    }

    @RequestMapping(value = "/student/deleteById/{id}")
    public ResponseUtil deleteById(@PathVariable("id") Integer id) {
        return studentService.deleteById(id);
    }

    @RequestMapping(value = "/student/deleteByIds")
    public ResponseUtil deleteById(Integer[] ids) {
        // return ResponseUtil.ok("批量删除成功", null);
        return studentService.deleteByIds(ids);
    }
}
